package com.cy;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

/**
 * 时间：2023/1/8
 */
@Component
@Aspect//将当前类标记为切面类
public class TimerAspect {
    /**
     *
     * @param pjp 表示接口的连接点，目标方法的对象
     * @return
     */
    @Around("execution(* com.cy.service.impl.*.*(..))")
    public Object Around(ProceedingJoinPoint pjp) throws Throwable {
        //先记录当前时间
        Long start = System.currentTimeMillis();
        Object result = pjp.proceed();//调用目标方法
        //后记录结束时间
        Long end = System.currentTimeMillis();
        System.out.println("耗时："+(end-start));
        return result;
    }
}
